/**
 * 字段字典表js
 */

$(function () {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-54});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url: '../../dict/table/list?_' + $.now(),
		height: $(window).height()-54,
		queryParams: function(params){
			params.name = vm.keyword;
			return params;
		},
		columns: [
			{checkbox: true},
			{field : "name", title : "字段名称", width : "100px"}, 
			{field : "code", title : "字段编码", width : "100px"}, 
			{field : "codeType", title : "字段类型", width : "100px"},
			{field : "remark", title : "字段备注", width : "120px"},
			{field : "createTime", title : "创建时间", width : "100px"}, 
			{field : "status", title : "状态", width : "80px",
				formatter : function(value, row, index) {
					if (value == '0') {
						return '<span class="label label-success">正常</span>';
					} else if (value == '1') {
						return '<span class="label label-danger">失效</span>';
					}
				}
			}
		]
	})
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
		keyword: null,
	},
	methods : {
		load: function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save: function() {
			dialogOpen({
				title: '新增字段字典表',
				url: 'base/dictTable/add.html?_' + $.now(),
				width: '620px',
				height: '450px',
				scroll:true,
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});

		},
		edit: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if(checkedRow(ck)){
				dialogOpen({
					title: '编辑字段字典表',
					url: 'base/dictTable/edit.html?_' + $.now(),
					width: '420px',
					height: '350px',
					success: function(iframeId){
						top.frames[iframeId].vm.dpTableColum.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes: function(iframeId){
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];	
			if(checkedArray(ck)){
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});
				dialogOpen({
					title: '编辑字段字典表',
					url: 'base/dictTable/edit.html?_' + $.now(),
					width: '420px',
					height: '350px',
					success: function(iframeId){
						top.frames[iframeId].vm.dpTableColum.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes: function(iframeId){
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		createTable: function() {

			var ck =$('#dataGrid').bootstrapTable('getSelections'), ids = [];
			if(checkedArray(ck)){
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});

				dialogOpen({
					title: '新增数据表',
					url: 'base/dictTable/create.html?_' + $.now(),
					width: '620px',
					height: '450px',
					scroll:true,
					yes : function(iframeId) {
						top.frames[iframeId].vm.ids =ids;
						top.frames[iframeId].vm.acceptClick();
					},
				});

			}
		}

	}
})